1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class KnightMovement : Movement, IPieceMovement {
6
7     
public KnightMovement(GCPlayer player, Piece piece) : base(player,piece) {
8         BoundComputations += ComputeBound;
9     }
10
11     
public override void ComputeBound() {
12         Node currNode = piece.Node;
13         
int origRow = currNode.row;
14         
int origCol = currNode.col;
15
16         Grid grid = GameManager.Instance.Grid;
17
18         
for (int row = -2; row <= 2; row++) {
19             
if (row == 0) continue;
20             
int col = GetCol(row, true);
21             
int newRow = origRow + row;
22             
int newCol = origCol + col;
23             Node newNode = grid.GetNodeAt(newRow,newCol);
24             ComputeMoveOrEatPiece(newNode);
25         }
26
27         
for (int row = -2; row <= 2; row++) {
28             
if (row == 0) continue;
29             
int col = GetCol(row, false);
30             
int newRow = origRow + row;
31             
int newCol = origCol + col;
32             Node newNode = grid.GetNodeAt(newRow,newCol);
33             ComputeMoveOrEatPiece(newNode);
34         }
35
36     }
37
38     
private int GetCol(int n, bool posSign) {
39         
if (Mathf.Abs(n) == 2) return 1 * ((posSign) ? 1 : -1);
40         
if (Mathf.Abs(n) == 1) return 2 * ((posSign) ? 1 : -1);
41         
return 0;
42     }
43 }


Gõ tìm kiếm nhanh...